//
//  AppDelegate.m
//  babyMemoryPro
//
//  Created by student on 15-6-23.
//  Copyright (c) 2015年 niit. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "LeftViewController.h"
#import "CoreNewFeatureVC.h"
#import "CALayer+Transition.h"
#import "DSHttpTool.h"
#import "DSAVStatus.h"
#import "LoginViewController.h"
#import "DSControllerTool.h"
#import "HeightViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "WXApi.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [DSAVStatus registerSubclass];
    [AVOSCloud setApplicationId:ApplicationID clientKey:ClientKey];
    self.window = window;
    
    //判断是否需要显示：（内部已经考虑版本及本地版本缓存）
    BOOL canShow = [CoreNewFeatureVC canShowNewFeature];
    
    //测试代码，正式版本应该删除
    
    if(canShow){
        
        NewFeatureModel *m1 = [NewFeatureModel model:[UIImage imageNamed:@"1.jpg"]];
        
        NewFeatureModel *m2 = [NewFeatureModel model:[UIImage imageNamed:@"2.jpg"]];
        
        NewFeatureModel *m3 = [NewFeatureModel model:[UIImage imageNamed:@"3.jpg"]];
        
        window.rootViewController = [CoreNewFeatureVC newFeatureVCWithModels:@[m1,m2,m3] enterBlock:^{
            
            NSLog(@"进入主页面");
            LoginViewController *vc=[[LoginViewController alloc]init];
            UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:vc];
            self.window.rootViewController=nav;
        }];
    }else{
        AVUser *currentUser = [AVUser currentUser];
        if (currentUser != nil){
            [self enter];
            NSLog(@"已登录");
  
        }else {
            LoginViewController *vc=[[LoginViewController alloc]init];
            self.window.rootViewController=vc;      
        }
        
    }
    
    
    
    [window makeKeyAndVisible];
    
    [ShareSDK registerApp:@"283279e3eee9"];
    [ShareSDK connectWeChatWithAppId:@"wx47e76b9f4606fa2b"        //此参数为申请的微信AppID
                           wechatCls:[WXApi class]];
    
    
    [[UINavigationBar appearance]setBarTintColor:[UIColor colorWithRed:244/255.0 green:201/255.0 blue:120/255.0 alpha:1.0]];
    
    [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:244/255.0 green:201/255.0 blue:120/255.0 alpha:1.0]];
    [self customApperance];
    
    
    
    return YES;
}
- (void)customApperance
{
    //自定义UISegmentControl
    UIImage *segmentSelected =
    [[UIImage imageNamed:@"6_seg.png"]
     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
    UIImage *segmentUnselected =
    [[UIImage imageNamed:@"7_seg.png"]
     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
    UIImage *segmentSelectedUnselected =
    [UIImage imageNamed:@"2_seg.png"];
    UIImage *segUnselectedSelected =
    [UIImage imageNamed:@"1_seg.png"];
    UIImage *segmentUnselectedUnselected =
    [UIImage imageNamed:@"3_seg.png"];
    
    [[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
                                               forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setBackgroundImage:segmentSelected
                                               forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    
    [[UISegmentedControl appearance] setDividerImage:segmentUnselectedUnselected
                                 forLeftSegmentState:UIControlStateNormal
                                   rightSegmentState:UIControlStateNormal
                                          barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
                                 forLeftSegmentState:UIControlStateSelected
                                   rightSegmentState:UIControlStateNormal
                                          barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance]
     setDividerImage:segUnselectedSelected
     forLeftSegmentState:UIControlStateNormal
     rightSegmentState:UIControlStateSelected
     barMetrics:UIBarMetricsDefault];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:127/255.0 green:86/255.0 blue:24/255.0 alpha:1.0],NSForegroundColorAttributeName, nil];
    
    [[UISegmentedControl appearance] setTitleTextAttributes:dict forState:UIControlStateNormal];
    [[UISegmentedControl appearance] setTitleTextAttributes:dict forState:UIControlStateSelected];
    
}

- (BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url
                        wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:self];
}

-(void)enter{
    MainViewController *mainVC = [MainViewController new];
    LeftViewController *leftVC = [[LeftViewController alloc] init];
    leftVC.selectedIndex = 0;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainVC];
    SLideZoomMenuController *slideZoomMenu = [[SLideZoomMenuController alloc] initWithRootController:nav];
    slideZoomMenu.leftViewController = leftVC;
    self.window.rootViewController = slideZoomMenu;
    self.slider = slideZoomMenu;
    
    
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
